package keeto.com.vn.bms.ui.adapter;

import java.util.ArrayList;

import keeto.com.vn.bms.model.ListSurgeryModel;
import keeto.com.vn.bms.ui.activity.R;
import keeto.com.vn.bms.utils.Utils;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ListSurgeryAdapter extends BaseAdapter{

	private Context mContext;
	private LayoutInflater mInflater;
	private ArrayList<ListSurgeryModel> mArrayList;

	public ListSurgeryAdapter(Context context,
			ArrayList<ListSurgeryModel> ArrayList) {
		super();
		this.mContext = context;
		this.mArrayList = ArrayList;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		ViewHolder holder;
		if (convertView == null){
			convertView = mInflater.inflate(R.layout.item_list_surgery_layout, null);
			holder = new ViewHolder();
			holder.rlPartent = (RelativeLayout)convertView.findViewById(R.id.rl_parent);
			holder.tv_item_surgery_name = (TextView)convertView.findViewById(R.id.tv_item_surgery_name);
			holder.tv_item_doctor_name = (TextView)convertView.findViewById(R.id.tv_item_doctor_name);
			holder.tv_item_hospital_name = (TextView)convertView.findViewById(R.id.tv_item_hospital_name);
			holder.tv_item_time = (TextView)convertView.findViewById(R.id.tv_item_time);
			holder.tv_item_status = (TextView)convertView.findViewById(R.id.tv_item_status);
			holder.ll_item_icon_status = (LinearLayout)convertView.findViewById(R.id.ll_item_icon_status);
			holder.tv_item_icon_status = (TextView)convertView.findViewById(R.id.tv_item_icon_status);
			holder.tv_item_icon_status.setVisibility(View.GONE);
			holder.imv_item_arrow = (ImageView)convertView.findViewById(R.id.imv_item_arrow);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		ListSurgeryModel model = mArrayList.get(position);
		holder.tv_item_surgery_name.setText(model.getSurgeryName());
		holder.tv_item_doctor_name.setText(model.getFullname());
		holder.tv_item_hospital_name.setText(model.getHospitalname());
		holder.tv_item_time.setText(Utils.convertTimeSurgery(model.getExecute_date()));
		holder.tv_item_status.setText(model.getSurgeryStatus());
		if (model.getSurgerySttId().equals("1")){
			holder.ll_item_icon_status.setBackgroundResource(R.drawable.icon_status_new);
			holder.tv_item_icon_status.setVisibility(View.VISIBLE);
			holder.tv_item_icon_status.setText(mContext.getResources().getString(R.string.tv_new));
			holder.imv_item_arrow.setVisibility(View.GONE);
			holder.rlPartent.setBackgroundColor(mContext.getResources().getColor(R.color.gray_hover));
		}else{
			holder.tv_item_icon_status.setVisibility(View.GONE);
			holder.imv_item_arrow.setVisibility(View.VISIBLE);
			holder.ll_item_icon_status.setBackgroundColor(Color.TRANSPARENT);
			holder.rlPartent.setBackgroundColor(Color.WHITE);

		}
		return convertView;
	}

	class ViewHolder{
		private RelativeLayout rlPartent;
		private TextView tv_item_surgery_name;
		private TextView tv_item_doctor_name;
		private TextView tv_item_hospital_name;
		private TextView tv_item_time;
		private TextView tv_item_status;
		private LinearLayout ll_item_icon_status;
		private TextView tv_item_icon_status;
		private ImageView imv_item_arrow;
	}
}
